$(function () {
	//JS代码网编辑整理：www.js-css.cn

	// 在线咨询
	var _hmt = _hmt || [];
	(function () {
		var hm = document.createElement("script");
		hm.src = "https://hm.baidu.com/hm.js?890d79b035f7362ba6fce448b1554191";
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(hm, s);
	})();

	// 获取文件名
	function pageName() {
		var a = location.href;
		var b = a.split("/");
		var c = b.slice(b.length - 1, b.length).toString(String).split(".");
		return c.slice(0, 1);
	}
	if (pageName()[0] === 'index') {
		// 二维码
		var freeTest = './html/freeTest.html'
		var wxCodeList = [{
			name: '颜经理',
			imgSrc: './assets/images/newAi/code01.png'
		}, {
			name: '叶经理',
			imgSrc: './assets/images/newAi/code02.png'
		}, {
			name: '彭经理',
			imgSrc: './assets/images/newAi/code03.png'
		}, {
			name: '林经理',
			imgSrc: './assets/images/newAi/code04.png'
		}, {
			name: '詹经理',
			imgSrc: './assets/images/newAi/code05.png'
		}, {
			name: '詹经理',
			phone: 18060470606,
			imgSrc: './assets/images/newAi/code06.png'
		}]
	} else {
		var freeTest = '../html/freeTest.html'
		var wxCodeList = [{
			name: '颜经理',
			phone: 18060768017,
			imgSrc: '../assets/images/newAi/code01.png'
		}, {
			name: '叶经理',
			phone: 18650051425,
			imgSrc: '../assets/images/newAi/code02.png'
		}, {
			name: '彭经理',
			phone: 18506927812,
			imgSrc: '../assets/images/newAi/code03.png'
		}, {
			name: '林经理',
			phone: 18046057263,
			imgSrc: '../assets/images/newAi/code04.png'
		}, {
			name: '詹经理',
			phone: 18350052496,
			imgSrc: '../assets/images/newAi/code05.png'
		}, {
			name: '詹经理',
			phone: 18060470606,
			imgSrc: '../assets/images/newAi/code06.png'
		}]
	}


	var phoneList = ['18060768017（颜经理）', '18060470606（詹经理）', '18350052496（詹经理）', '18046057263（林经理）', "18506927812（彭经理）", "18650051425（叶经理）"], // 电话咨询
		cooperationList = ['18046057263（林经理）', '18060768017（颜经理）', "18650051425（叶经理）", '18506927812（彭经理）'] // 合作

	function randomsort(a, b) {
		return Math.random() > .5 ? -1 : 1;
	}
	phoneList = phoneList.sort(randomsort)
	wxCodeList = wxCodeList.sort(randomsort)
	cooperationList = cooperationList.sort(randomsort)
	$('.company-code').attr('src', wxCodeList[0].imgSrc)
	var wxCodeListHtml = '',
		phoneListHtml = ''
	// 随机二维码
	wxCodeList.forEach(function (item) {
		wxCodeListHtml += '<div class="img-src-contain"><img src=' + item.imgSrc + '><p>' + item.name + '</p></div>'
	})
	// 联系我们页面
	wxCodeList.forEach(function (item) {
		$('#contact-wxCode').append('<div class="am-u-md-4 am-margin-bottom am-padding-left-lg am-padding-right-lg" style="float: left">' +
			'<div class="font-12 am-text-center">销售经理：' + item.name + '</div>' +
			'<div class="font-12 am-text-center"><i class="uspo-ico"></i>' + item.phone + '</div>' +
			'<div><img src=' + item.imgSrc + '> </div>' +
			'<div class="font-12 color-99 am-text-center">(扫码添加微信）</div></div>')
	})
	phoneList.forEach(function (item) {
			phoneListHtml += '<p class=\"phone-lists\">' + item + '</p>'
		}),
		cooperationList.forEach(function (item, index) {
			if (index === 0) {
				$('#cooperation-list').append('<p class="footer-p1">合作：' + item + '</p>')
			} else {
				$('#cooperation-list').append('<p class="footer-p2">' + item + '</p>')
			}
		})

	var tophtml = "<div id=\"izl_rmenu\" class=\"izl-rmenu\">" +
		'<div class=\"btn btn-wx icon-tab_try iconfont\" ><p>微信咨询</p><div class=\"pic\"><p class=\"wx-title\">扫一扫微信咨询</p><div class=\"wx-img\">' +
		wxCodeListHtml + '</div></div></div>' +
		'<div class=\"btn btn-phone icon-tab_call iconfont\"><p>电话咨询</p><div class=\"phone\"><p class=\"phone-title\">vip专线</p>' + phoneListHtml + '</div></div>' +
		"<div class=\"btn btn-wx icon-tab_sqsy iconfont\" data-am-modal=\"{target: '#apply-test'}\"><p>申请试用</p></div>" +
		"<a href=" + freeTest + "><div class=\"btn btn-wx icon-tab_sqzc iconfont\" \"><p>免费体验</p></div></a>";

	$("#top").html(tophtml);
	$("#izl_rmenu").each(function () {
		$(this).find(".btn-wx").mouseenter(function () {
			$(this).find(".pic").fadeIn("fast");
		});
		$(this).find(".btn-wx").mouseleave(function () {
			$(this).find(".pic").fadeOut("fast");
		});
		$(this).find(".btn-phone").mouseenter(function () {
			$(this).find(".phone").fadeIn("fast");
		});
		$(this).find(".btn-phone").mouseleave(function () {
			$(this).find(".phone").fadeOut("fast");
		});
		$(this).find(".btn-top").click(function () {
			$("html, body").animate({
				"scroll-top": 0
			}, "fast");
		});
	});

	// 提交表单
	$('body').append('<div class="am-modal am-modal-no-btn " tabindex="-1"  id="apply-test" style="display: none;">' +
		'<div class="am-modal-dialog" style="width: 500px;height: 470px;">' +
		'<div class="am-modal-hd modal-title">申请试用' +
		'<a class="am-close  modal-close" data-am-modal-close=""></a></div>' +
		'<div class="am-modal-bd modal-body"><form action="" class="am-form">' +
		'<div class="am-form-group"><label><span class="red-xing">*</span>电话：</label><input type="number" id="phones" placeholder="请填写您的电话" class="form-control"></div>' +
		'<div class="am-form-group"><label><span class="red-xing">*</span>验证码:</label><br/><input type="number"  id="code1" placeholder="请输入您的验证码" class="form-control"><input type="button" class="send-code1" value="获取验证码"></input></div>' +
		'</form></div>' +
		'<div class="modal-footer"><input type="submit" class="btn btn-primary btn-submit btn-submit-test" onclick="applyTest()" value="提交"></div></div></div>')

	var timer, time = 60

	$('.send-code1').click(function () {
		clearInterval(timer)
		if ($('#phones').val().match(
				/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) ===
			null) {
			alert('请正确填写您的手机号码')
			return
		}
		$('.send-code1').attr('disabled', true)
		timer = setInterval(function () {
			time -= 1
			if (time === 0) {
				$('.send-code1').attr('disabled', false)
				time = 60
				$('.send-code1').val('重新获取')
				clearInterval(timer)
				return

			}
			$('.send-code1').val(time + 's后')

		}, 1000)
		$.ajax({
			url: 'https://proxfix.vmajy.com/api/apply/code',
			type: 'post',
			data: JSON.stringify({
				mobile: $('#phones').val(),
			}),
			dataType: "json",
			headers: {
				'Content-Type': 'application/json;charset=UTF-8'
			},
			success: function (data) {
				if (data.result_code == 0) {
					alert('您好，我们经理将尽快联系您，请留意福州号码。')
					$(".am-dimmer").click()
				} else {
					alert(data.result_msg)
					$(".am-dimmer").click()
				}
			}
		})
	})

	window.applyTest = function () {
		if ($('#phones').val().match(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) === null) {
			alert('请正确填写您的手机号码，方便我们与您联系')
			return
		}


		$.ajax({
			url: 'https://proxfix.vmajy.com/api/apply/new/add',
			type: 'post',
			data: JSON.stringify({
				mobile: $('#phones').val(),
				projectName: '微码微控',
				code: $('#code1').val(),
				machineType: 1,
				applyType: 2,
				platformId: 0
			}),
			dataType: "json",
			headers: {
				'Content-Type': 'application/json;charset=UTF-8'
			},
			success: function (data) {
				if (data.result_code == 0) {
					alert('您好，我们经理将尽快联系您，请留意福州号码。')
					$(".am-dimmer").click()
				} else {
					alert(data.result_msg)
					$(".am-dimmer").click()
				}
			},
			error: function (err) {
				alert(err.responseJSON.err_msg)
			}
		})
	}

	// 产品下拉
	$('.hover-active').hover(function () {
		$('.hover-nav').show()
	}, function () {
		$('.hover-nav').hide()
	})

	$('.hover-nav').hover(function () {
		$('.hover-nav').show()
	}, function () {
		$('.hover-nav').hide()
	})

	/* 	var lastRmenuStatus = false;
		$(window).scroll(function () { //bug
			var _top = $(window).scrollTop();
			if (_top > 200) {
				$("#izl_rmenu").data("expanded", true);
			} else {
				$("#izl_rmenu").data("expanded", false);
			}
			if ($("#izl_rmenu").data("expanded") != lastRmenuStatus) {
				lastRmenuStatus = $("#izl_rmenu").data("expanded");
				if (lastRmenuStatus) {
					$("#izl_rmenu .btn-top").slideDown();
				} else {
					$("#izl_rmenu .btn-top").slideUp();
				}
			}
		}); */
});